import 'package:easy_read_comic/controller/app_controller.dart';
import 'package:easy_read_comic/controller/me/me_controller.dart';
import 'package:easy_read_comic/widgets/auto_image_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class _settingEntity {
  _settingEntity(
    this.title,
    this.subtitle,
    this.color,
    this.icon, {
    GestureTapCallback? this.Caller = null,
  });

  String title;

  String subtitle;

  Color color;

  IconData icon;

  GestureTapCallback? Caller = null;
}

class MeView extends StatelessWidget {
  final List<_settingEntity> list = [
    _settingEntity(
      "帮找漫画",
      "想要的漫画都有",
      Colors.purple.shade100,
      Icons.search,
      Caller: () {
        Get.toNamed("/comic_look_for");
      },
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      builder: (controller) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Theme.of(context).primaryColor,
            actions: [
              IconButton(
                onPressed: () => Get.toNamed('/setting'),
                icon: Icon(
                  Icons.settings,
                  color: Colors.white,
                ),
              ),
            ],
          ),
          body: Container(
            child: Column(
              children: [
                Stack(
                  children: [
                    Container(
                      height: 250,
                    ),
                    Container(
                      height: 200,
                      decoration: BoxDecoration(
                        color: Theme.of(context).primaryColor,
                        borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(50),
                          bottomRight: Radius.circular(50),
                        ),
                      ),
                    ),
                    Positioned(
                      child: Container(
                        height: 130,
                        width: Get.width,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          boxShadow: [
                            BoxShadow(
                              color: Theme.of(context).primaryColor,
                              blurRadius: 10,
                            ),
                          ],
                          borderRadius: BorderRadius.circular(10),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Column(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: [
                                Icon(
                                  Icons.attach_money_sharp,
                                  color: Colors.yellow,
                                  size: 50,
                                ),
                                Text(
                                  "0.00",
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                      bottom: 0,
                      left: 40,
                      right: 40,
                    ),
                    Positioned(
                      child: GestureDetector(
                        child: Container(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Container(
                                height: 80,
                                width: 80,
                                child: ClipRRect(
                                  child: AutoImage.buildImage(
                                    AppController().User!.Avatar,
                                  ),
                                  borderRadius:
                                      BorderRadius.all(Radius.circular(50)),
                                ),
                              ),
                              Container(
                                padding: EdgeInsets.only(
                                  left: 10,
                                ),
                                child: Column(
                                  children: [
                                    Text(
                                      AppController().IsLoginState
                                          ? AppController().User!.NickName
                                          : "点击登录",
                                      style: TextStyle(
                                        fontSize: 18,
                                        color: Colors.white,
                                      ),
                                    ),
                                    Text(
                                      "用魔法改变未来的小太阳",
                                      style: TextStyle(
                                        color: Colors.white54,
                                      ),
                                    ),
                                  ],
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                ),
                              ),
                              Container(
                                child: IconButton(
                                  onPressed: () {},
                                  icon: Icon(
                                    Icons.chevron_right,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ],
                          ),
                          width: Get.width,
                        ),
                        onTap: () {
                          if (!AppController().IsLoginState) {
                            Get.toNamed('/login_with_register');
                          } else {
                            return null;
                          }
                        },
                      ),
                    ),
                  ],
                ),
                Container(
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      color: Colors.white,
                      boxShadow: [
                        BoxShadow(
                          color: Theme.of(context).primaryColor,
                          blurRadius: 10,
                          offset: Offset(0, 5),
                        ),
                      ],
                    ),
                    padding: EdgeInsets.zero,
                    margin: EdgeInsets.zero,
                    child: GridView.builder(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2,
                        crossAxisSpacing: 10.0,
                        mainAxisSpacing: 0.0,
                        childAspectRatio: 1.2,
                      ),
                      itemCount: list.length,
                      itemBuilder: (context, index) {
                        return GestureDetector(
                          child: Container(
                            padding: EdgeInsets.all(10),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: [
                                Container(
                                  child: Icon(
                                    list[index].icon,
                                    color: list[index].color,
                                  ),
                                  padding: EdgeInsets.all(15),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(50),
                                    color: list[index].color.withOpacity(0.1),
                                  ),
                                ),
                                Container(
                                  child: Text(
                                    list[index].title,
                                    style: TextStyle(
                                      fontSize: 16,
                                    ),
                                  ),
                                  padding: EdgeInsets.only(
                                    top: 5,
                                  ),
                                ),
                                Container(
                                  child: Text(
                                    list[index].subtitle,
                                    style: TextStyle(
                                      fontSize: 10,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          onTap: list[index].Caller,
                        );
                      },
                    ),
                  ),
                  padding: EdgeInsets.only(
                    left: 20,
                    right: 20,
                  ),
                  margin: EdgeInsets.only(
                    top: 20,
                  ),
                ),
              ],
            ),
          ),
        );
      },
      init: MeController(),
    );
  }
}
